﻿using UnityEngine;

/// <summary>
/// 
/// </summary>
public class SprintComponent : MonoBehaviour
{
    [SerializeField] private float sprintMultiplier = 1.5f;
    [SerializeField] private float staminaDrain = 10f;

    private MovementComponent _movement;
    private bool _isSprinting;

    void Awake()
    {
        _movement = GetComponent<MovementComponent>();

        GetComponent<InputHandler>().OnSprintPressed += StartSprinting;
        GetComponent<InputHandler>().OnSprintReleased += StopSprinting;
    }

    void StartSprinting()
    {
        if (!_isSprinting)
        {
            _movement.AddSpeedModifier(sprintMultiplier);
            _isSprinting = true;
        }
    }

    void StopSprinting()
    {
        if (_isSprinting)
        {
            _movement.RemoveSpeedModifier(sprintMultiplier);
            _isSprinting = false;
        }
    }
}